home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / FINGER.C < prev    next >
Text File  |  1993-08-09  |  1KB  |  64 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "socket.h"
  6. #include "session.h"
  7. #include "proc.h"
  8. #include "netuser.h"
  9. #include "commands.h"
  10. #include "tty.h"
  11.  
  12. int
  13. dofinger(int argc,char **argv,void *p)
  14. {
  15.     struct sockaddr_in sock;
  16.     char *cp;
  17.     int i;
  18.     struct mbuf *bp;
  19.     struct session *sp;
  20.  
  21.     /* Allocate a session descriptor */
  22.     if((sp = newsession(argv[1],FINGER,SWAP)) == NULLSESSION){
  23.         tputs(Nosess);
  24.         return 1;
  25.     }
  26.     sp->ttystate.echo = sp->ttystate.edit = 0;
  27.     sp->flowmode = Cooked;
  28.     sock.sin_family = AF_INET;
  29.     sock.sin_port = IPPORT_FINGER;
  30.  
  31.     for(i = 1; i < argc; i++) {
  32.         if((cp = strchr(argv[i],'@')) == NULLCHAR) {
  33.             tprintf("%s: local names not supported\n",argv[i]);
  34.             continue;
  35.         }
  36.         *cp++ = '\0';
  37.  
  38.         tprintf("%s@%s -- Resolving %s... ",argv[i],cp,cp);
  39.  
  40.         if((sock.sin_addr.s_addr = resolve(cp)) == 0){
  41.             tprintf(Badhost,cp);
  42.             continue;
  43.         }
  44.         if((sp->s = socket(AF_INET,SOCK_STREAM,0)) == -1){
  45.             tputs(Nosocket);
  46.             break;
  47.         }
  48.         sockmode(sp->s,SOCK_ASCII);
  49.         tprintf("Trying %s...",psocket((struct sockaddr *)&sock));
  50.  
  51.         if(connect(sp->s,(char *)&sock,SOCKSIZE) != -1) {
  52.             tputs("\n");
  53.             usprintf(sp->s,"%s\n",argv[i]);
  54.             usflush(Curproc->output);
  55.             while(recv_mbuf(sp->s,&bp,0,NULLCHAR,0) > 0) {
  56.                 send_mbuf(Curproc->output,bp,0,NULLCHAR,0);
  57.             }
  58.         }
  59.     }
  60.     keywait(NULLCHAR,1);
  61.     freesession(sp);
  62.     return 0;
  63. }
  64.